import {Component, EventEmitter, OnInit, Output} from '@angular/core';
import { Router } from '@angular/router';
import { DomSanitizer } from "@angular/platform-browser";
import { HttpClient } from '@angular/common/http';
import {MenuComponent} from "../menu/menu.component";

@Component({
  selector: 'app-header',
  templateUrl: './header.component.html',
  styleUrls: ['./header.component.css']
})
export class HeaderComponent implements OnInit{
  addressUrl :string =  location.pathname;//本地地址路径
  menuList:Array<any>;
  private  title :string = "环境在线监测监控数据采集与交换系统";//标题

  @Output()
  sendMenu:EventEmitter<any> = new EventEmitter();


	constructor(private http: HttpClient,public router:Router,private sanitizer: DomSanitizer){ }
	ngOnInit(){

	}

  logout(){//退出登录弹框
    $("#loginOut").modal('show');
  }
  resetUser(){//确认退出 清理相关用户信息吧并跳转到登录页面。
    this.router.navigate(['/login']);
    sessionStorage["UserId"] = "";
    $("#loginOut").modal('hide');
  }

  changeMenu($event){
    let system = $event.target.name;
    if(system=="emis"){//基础
      this.http.get('api/emisMenu.json').subscribe(data => {
        if(data['result'].resultCode = "00000000"){
          this.menuList = data['menuList'];
          this.sendMenu.emit(this.menuList);
          this.router.navigate(['/index/home']);
          this.title = "环境基础管理信息系统";
        }else{
          alert("失败！")
        }
      });
    }else if(system=="communication"){//采集
      this.http.get('api/communicationMenu.json').subscribe(data => {
        if(data['result'].resultCode = "00000000"){
          this.menuList = data['menuList'];
          this.sendMenu.emit(this.menuList);
          this.router.navigate(['/index/home']);
          this.title="环境在线监测监控数据采集与交换系统";
        }else{
          alert("失败！")
        }
      });
    }else if(system=="dims"){//监控
      this.http.get('api/dimsMenu.json').subscribe(data => {
        if(data['result'].resultCode = "00000000"){
          this.menuList = data['menuList'];
          this.sendMenu.emit(this.menuList);
          this.router.navigate(['/index/home']);
          this.title = "环境监测监控动态信息管理系统";
        }else{
          alert("失败！")
        }
      });
    }



  }


}
